from apps.common.base.serializers import *
from apps.education.student.models import *


class StudentBaseSerializer(BaseSerializer):
    class Meta:
        model = Student
        fields = "__all__"


class StudentModelSerializer(StudentBaseSerializer):

    userModel = serializers.SerializerMethodField()
    def get_userModel(self, obj):
        try:
            return {'id': obj.user.id, 'username': obj.user.username, 'code': obj.user.code}
        except:
            return {}
        
    typesLabel = serializers.SerializerMethodField()

    def get_typesLabel(self, obj):
        try:
            return obj.get_types_display()
        except:
            return '未知'

    class Meta:
        model = Student
        fields = "__all__"
